<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>用户绑定</title>
</head>
<link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
<link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">

<link rel="stylesheet" href="../../src/dist/css/page.css">

<body>
<div class="weui-cells user-binding">
    <div class="weui-cells__tips">用户信息页</div>
    <!--<div class="weui-cell">
        <div class="weui-cell__hd">
            <i class="iconfont iconjiage"></i>
        </div>
        <div class="weui-cell__bd">
            <p>燃气费</p>
        </div>
        <div class="weui-cell__ft"></div>
    </div>-->
    <div class="weui-cell">
        <div class="weui-cell__hd">
            <i class="iconfont iconzhanghao"></i>
        </div>
        <div class="weui-cell__bd">
            <p>用户号</p>
        </div>

        <div class="weui-cell__bd">
            <input class="weui-input" type="number" pattern="[0-9]*" placeholder="请输入用户账号" id="usercode">
        </div>
    </div>
    <div class="button_sp_area">
        <a href="javascript:;" class="weui-btn weui-btn_primary" onclick="binDingAction()">绑定</a>
    </div>
</div>

<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>

<!-- Dist -->
<script src="../../src/dist/js/index.js"></script>
<script src="../../src/dist/js/utils.js"></script>
<script src="../../src/dist/js/request.js"></script>
<script>
    var openid = '';
    $(function(){
        var paras = location.search;            //search获得地址中的参数，内容为'?itemId=12'
        var result = paras.match(/[^\?&]*=[^&]*/g);     //match是字符串中符合的字段一个一个取出来，result中的值为['login=xx','table=admin']
        paras = {};                    //让paras变成没有内容的json对象
        for (i in result) {
            var temp = result[i].split('=');    //split()将一个字符串分解成一个数组,两次遍历result中的值分别为['itemId','xx']
            paras[temp[0]] = temp[1];
        }
        openid = paras.openid;     //根据参数名"itemId"，获取参数值
    })


    function binDingAction(){
      let usercode = $("#usercode").val()
      if(usercode === ''){
        // $.toast("用户号不能为空", "text")
        return
      }
        var reg = /^\d{10}$/
        if (!reg.test(usercode)) {
			$.toast("用户号格式不正确", "text");
            return false
        }

        get("/wechat/binding/saveBinding?openid=" + openid + '&usercode='+ usercode, {}, function (data) {
            if (data.code === 0) {
                location.href = './bangdingList.html'
            } else {
                $.toast('绑定失败!', 'forbidden');
            }
        }, false, true);

    }
</script>
</body>
</html>
